<?php
	require_once 'connection.php';
	class Product{
		static function redirectTo($page){
			$host=$_SERVER['HTTP_HOST'];
			$uri= rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
			header("Location: http://$host/$uri/$page");
			exit();
		}
		/*Thong ke*/
		
			
			
		/*Brand*/
		//check brand in database
		static function checkBrand($brandName){
			$query="SELECT * FROM tbl_brand WHERE brandName='$brandName'";
			$result =mysql_query($query) or die("checkBrand:".mysql_error());
			$num=mysql_num_rows($result);
			if($num==0) return true;
			else return false;
		}
		static function getBrandInfo($brandID){
			$query="SELECT * FROM tbl_brand WHERE brandID='$brandID'";
			$result=mysql_query($query) or die("getBrandInfo".mysql_error());
			$row=mysql_fetch_array($result);
			return $row;
		}	
		//insert a new brand
		static function insertBrand($brandName,$image){
			$brandName=mysql_real_escape_string(trim($brandName));
			$image=mysql_real_escape_string(trim($image));
			$time="U";
			$status="1";
			$query="INSERT INTO tbl_brand(brandName,br_image,status,time) VALUES('$brandName','$image',$status,'$time')";
			$result=mysql_query($query) or die("InsertBrand:".mysql_error());
			return $result;
		}
		//update abrand
		static function updateBrand($brandID,$brandName,$br_image,$br_status){
			$brandID=mysql_real_escape_string(trim($brandID));
			$brandName=mysql_real_escape_string(trim($brandName));
			$br_image=mysql_real_escape_string(trim($br_image));
			$br_status=mysql_real_escape_string(trim($br_status));
			$time="U";
			$query="UPDATE tbl_brand SET brandName='$brandName',br_image='$br_image',br_status='$br_status',time='$time' WHERE brandID='$brandID'";
			$result=mysql_query($query) or die("UpdateBrand:".mysql_error());
			return $result;
		}
		//Del a brand
		static function delBrand($brandID){
			$query="DELETE FROM tbl_brand WHERE brandID='$brandID'";
			$result=mysql_query($query) or die("DelBrand: ".mysql_error());
			return $result;
		}
		//print brand table
		static function printBrandTable($brandName){
			if ($brandName == "") $brand_cond = "true";
			else $brand_cond = "brandName='$brandName'";
			$query = "SELECT * FROM tbl_brand WHERE $brand_cond ORDER BY brandName ASC";
			$result = mysql_query($query)or die("printBrandTable: ".mysql_error());
			print ('<table id="hor-zebra">
			<thread><tr>
				<th>ID</th>
				<th>Brand</th>
				<th>Image</th>
				<th>Status</th>
				<th colspan="3">Action</th>
			</tr></thread>
			');
			while($row=mysql_fetch_array($result)){
				print('<tbody><tr>
							<td>'.$row['brandID'].'</td>
							<td>'.$row['brandName'].'</td>
							<td><img src='.$row['br_image'].'></td>
							<td>'.$row['br_status'].'</td>
							<td><a href="../admin/update_brand.php?brandID='.$row['brandID'].'">Update</a></td>
							<td><a type="submit" href="../admin/del_brand.php?brandID='.$row['brandID'].'" >Delete</a></td>
							</tr>');}
			print('</tbody></table>');
		}
		//print Brand drop
		static function printBrandDrop($brandID){
			$query = "SELECT * FROM tbl_brand ORDER BY brandName ASC";
			$result = mysql_query($query)or die("printBrandDrop: ".mysql_error());
			while ($row	= mysql_fetch_array($result)) {
				if($row['brandID']==$brandID)print('<option value="'.$row['brandID'].'" selected>'.$row['brandName'].'</option>');
				else print('<option value="'.$row['brandID'].'">'.$row['brandName'].'</option>');
			}
			
		}
		/*model*/
		//checkModel
			/*Model*/
				//lấy thông tin model
		static function getModelInfo($modelID){
			$query="SELECT * FROM tbl_model md,tbl_brand brs WHERE md.brandID=brs.brandID AND modelID='$modelID'";
			$result=mysql_query($query) or die("getModelInfo".mysql_error());
			$row=mysql_fetch_array($result);
			return $row;
		}	
		//cập nhật model
		static function updateModel($modelID,$modelName){
			$modelID=mysql_real_escape_string(trim($modelID));
			$modelName=mysql_real_escape_string(trim($modelName));
			$query="UPDATE tbl_model SET modelName='$modelName' WHERE modelID='$modelID'";
			$result=mysql_query($query) or die("updateModel: ".mysql_error());
			return $result;
		}
		
		static function checkModel($brandID,$modelName){
			$modelName 	= mysql_real_escape_string($modelName);
			$query 	= "SELECT * FROM tbl_model WHERE brandID='$brandID' AND modelName='$modelName'";
			$result = mysql_query($query)or die("checkModel: ".mysql_error());
			$num 	= mysql_num_rows($result);
			if ($num == 0) return true;
			else return false;
		}
		//insert a New Model
		static function insertModel($brandID,$modelName){
			$modelName 	= mysql_real_escape_string($modelName);
			$time  	= date('U');
			$query 	= "INSERT INTO tbl_model(brandID,modelName,time) VALUES($brandID,'$modelName',$time)";
			$result = mysql_query($query)or die("insertModel: ".mysql_error());
			return $result;
		}
		//Del a model
		static function delModel($modelID){
			$query="DELETE FROM tbl_model WHERE modelID='$modelID'";
			$result=mysql_query($query) or die("DelModel: ".mysql_error());
			return $result;
		}
		//print a Model Table
		static function printModelTable($brandID){
			if ($brandID == "") $cond_brand = true;
			else $cond_brand = "brandID='$brandID'";
			$query = "SELECT * FROM tbl_model md,tbl_brand br WHERE $cond_brand and br.brandID=md.brandID  ORDER BY modelName ASC";
			$result = mysql_query($query)or die("printModelTable: ".mysql_error());
			$num = mysql_num_rows($result);
			print ('<table id="hor-zebra">
			<thread><tr>
				<th>ID</th>
				<th>Brand</th>
				<th>Model</th>
				<th colspan="3">Action</th>
			</tr></thread>
			');
			while($row=mysql_fetch_array($result)){
				print('<tbody><tr>
							<td>'.$row['modelID'].'</td>
							<td>'.$row['brandName'].'</td>
							<td>'.$row['modelName'].'</td>
							<td><a href="../admin/update_model.php?modelID='.$row['modelID'].'">Update</a></td>
							<td><a href="../admin/del_model.php?modelID='.$row['modelID'].'">Delete</a></td>
							
							</tr>');}
			print('</tbody></table>');
		}	
		//print Model drop
		static function printModelDrop($brandID){
		if ($brandID == "") $brand_cond = "true";
		else $brand_cond = "brandID='$brandID'";
		$query = "SELECT * FROM tbl_model WHERE $brand_cond ORDER BY modelName ASC";
		$result = mysql_query($query)or die("printModelDrop: ".mysql_error());
		print ('<select id="modelID" name="modelID" onchange="printSeriesDrop();" ><option value="">All Model</option>');
		while ($row	= mysql_fetch_array($result)) {
			print('<option value="'.$row['modelID'].'">'.$row['modelName'].'</option>');
		}
		print ('</select>');
		}
		//Hien thi model san co
		static function printModelDrop2($brandID,$modelID){
		if ($brandID == "") $brand_cond = "true";
		else $brand_cond = "brandID='$brandID'";
		$query = "SELECT * FROM tbl_model WHERE $brand_cond ORDER BY modelName ASC";
		$result = mysql_query($query)or die("printModelDrop: ".mysql_error());
		while ($row	= mysql_fetch_array($result)) {
			if($row['modelID']==$modelID)print('<option value="'.$row['modelID'].'"selected>'.$row['modelName'].'</option>');
			else print('<option value="'.$row['modelID'].'">'.$row['modelName'].'</option>');
		}
		}
		
		//print Series drop
		static function printSeriesDrop($modelID){
			if ($modelID == "") $model_cond = "true";
			else $model_cond = "modelID='$modelID'";
			$query = "SELECT * FROM tbl_series WHERE $model_cond ORDER BY seriesName ASC";
			$result = mysql_query($query)or die("printSeriesDrop: ".mysql_error());
			print ('<select id="seriesID" name="seriesID"><option>All Series</option>');
			while ($row	= mysql_fetch_array($result)) {
				print('<option value="'.$row['seriesID'].'">'.$row['seriesName'].'</option>');
			}
			print ('</select>');
		}
		//print Series drop sẵn có
		static function printSeriesDrop2($modelID,$seriesID){
			if ($modelID == "") $model_cond = "true";
			else $model_cond = "modelID='$modelID'";
			$query = "SELECT * FROM tbl_series WHERE $model_cond ORDER BY seriesName ASC";
			$result = mysql_query($query)or die("printSeriesDrop: ".mysql_error());
			while ($row	= mysql_fetch_array($result)) {
				if($row['seriesID']==$seriesID)print('<option value="'.$row['seriesID'].'"selected>'.$row['seriesName'].'</option>');
				else print('<option value="'.$row['seriesID'].'">'.$row['seriesName'].'</option>');
			}
		}
		/*Series*/
		//checkSeries
		static function getSeriesInfo($seriesID){
			$query="SELECT * FROM tbl_brand brs,tbl_model md,tbl_series sr WHERE brs.brandID=md.brandID AND md.modelID=sr.modelID AND seriesID='$seriesID'";
			//echo $query;
			$result=mysql_query($query) or die("getSeriesInfo".mysql_error());
			$row=mysql_fetch_array($result);
			return $row;
		}	
		static function checkSeries($modelID,$brandID,$seriesName){
			$modelID 	= mysql_real_escape_string($modelID);
			$brandID 	= mysql_real_escape_string($brandID);
			$seriesName 	= mysql_real_escape_string($seriesName);
			$query 	= "SELECT * FROM tbl_series WHERE modelID='$modelID' AND brandID='$brandID' AND seriesName='$seriesName'";
			$result = mysql_query($query)or die("checkSeries: ".mysql_error());
			$num 	= mysql_num_rows($result);
			if ($num == 0) return true;
			else return false;
		}
		static function listSeries(){
			$query= "SELECT * FROM tbl_series sr,tbl_model md,tbl_brand br WHERE br.brandID=md.brandID and md.modelID=sr.modelID";
			$result =mysql_query($query) or die ("listseries: ".mysql_error());
			print ('<table id="hor-zebra">
			<thread><tr>
				<th>ID</th>
				<th>Brand name</th>
				<th>Model name</th>
				<th>Series name</th>
				<th colspan="3">Action</th>
			</tr></thread>
			');
			while($row=mysql_fetch_array($result)){
				print('<tbody><tr>
							<td>'.$row['seriesID'].'</td>
							<td>'.$row['brandName'].'</td>
							<td>'.$row['modelName'].'</td>
							<td>'.$row['seriesName'].'</td>
							<td><a href="../admin/update_series.php?seriesID='.$row['seriesID'].'">Update</a></td>
							<td><a href="../admin/del_series.php?seriesID='.$row['seriesID'].'">Delete</a></td>
							
							</tr>');}
			print('</tbody></table>');
		}	
		//insert a New Series
		static function insertSeries($modelID,$brandID,$seriesName){
			$modelID 	= mysql_real_escape_string($modelID);
			$brandID 	= mysql_real_escape_string($brandID);
			$seriesName 	= mysql_real_escape_string($seriesName);
			$query 	= "INSERT INTO tbl_series(modelID,brandID,seriesName) VALUES($modelID,$brandID,'$seriesName')";
			$result = mysql_query($query)or die("insertSeries: ".mysql_error());
			return $result;
		}
		//update series
		static function updateSeries($seriesID,$seriesName){
			$seriesID=mysql_real_escape_string(trim($seriesID));
			$seriesName=mysql_real_escape_string(trim($seriesName));
			$query="UPDATE tbl_series SET seriesName='$seriesName' WHERE seriesID='$seriesID'";
			$result=mysql_query($query) or die("updateseries: ".mysql_error());
			return $result;
		}
		//Del a series
		static function delSeries($seriesID){
			$query="DELETE FROM tbl_series WHERE seriesID='$seriesID'";
			$result=mysql_query($query) or die("DelSeries: ".mysql_error());
			return $result;
		}
		//print a Series Table
		static function printSeriesTable($modelID){
			if ($modelID == "") $cond_model = true;
			else $cond_model = "md.modelID='$modelID'";
			//$query = "SELECT * FROM tbl_series WHERE $cond_model ORDER BY seriesName ASC";
			$query= "SELECT * FROM tbl_series sr,tbl_model md,tbl_brand br WHERE br.brandID=md.brandID and md.modelID=sr.modelID ORDER BY seriesName ASC";
			$result = mysql_query($query)or die("printSeriesTable: ".mysql_error());
			print ('<table id="hor-zebra">
			<thread><tr>
				<th>ID</th>
				<th>Brand name</th>
				<th>Model name</th>
				<th>Series name</th>
				<th colspan="3">Action</th>
			</tr></thread>
			');
			while($row=mysql_fetch_array($result)){
				print('<tbody><tr>
							<td>'.$row['seriesID'].'</td>
							<td>'.$row['brandName'].'</td>
							<td>'.$row['modelName'].'</td>
							<td>'.$row['seriesName'].'</td>
							<td><a href="../admin/update_series.php?seriesID='.$row['seriesID'].'">Update</a></td>
							<td><a href="../admin/del_series.php?seriesID='.$row['seriesID'].'">Delete</a></td>
							
							</tr>');}
			print('</tbody></table>');
		}
		/*Product*/
		static function getInfoProduct_($productID){
			$query="SELECT * FROM tbl_product pr, tbl_brand br,tbl_model md,tbl_series sr WHERE
			pr.brandID=br.brandID AND 
			pr.modelID=md.modelID AND 
			pr.seriesID=sr.seriesID AND 
			pr.productID='$productID' GROUP BY pr.brandID,pr.modelID,pr.seriesID";
			$result=mysql_query($query) or die("getInfoProduct: ".mysql_error());
			$row=mysql_fetch_array($result);
			return $row;
		}
		
		static function getInfoProduct($productID){
			$query="SELECT * FROM tbl_product pr, tbl_brand br,tbl_model md,tbl_series sr,tbl_product_detail pr_dt WHERE
			pr.productID=pr_dt.productID AND
			pr.brandID=br.brandID AND 
			pr.modelID=md.modelID AND 
			pr.seriesID=sr.seriesID AND 
			pr.productID='$productID' GROUP BY pr.brandID,pr.modelID,pr.seriesID";
			$result=mysql_query($query) or die("getInfoProduct: ".mysql_error());
			$row=mysql_fetch_array($result);
			return $row;
		}
		static function getInfoProduct_series($seriesID){
			$query="SELECT * FROM tbl_product pr, tbl_brand br,tbl_model md,tbl_series sr WHERE
			pr.brandID=br.brandID AND pr.modelID=md.modelID AND pr.seriesID=sr.seriesID AND	pr.seriesID='$seriesID' GROUP BY pr.brandID,pr.modelID,pr.seriesID";
			$result=mysql_query($query) or die("getInfoProduct_series: ".mysql_error());
			$row=mysql_fetch_array($result);
			return $row;
		}
		
		static function checkProduct($brandID,$modelID,$seriesID){
			$brandID=mysql_real_escape_string(trim($brandID));
			$modelID=mysql_real_escape_string(trim($modelID));
			$seriesID=mysql_real_escape_string(trim($seriesID));
			$query="SELECT * FROM tbl_product WHERE brandID='$brandID' AND modelID='$modelID' AND seriesID='$seriesID'";
			$result =mysql_query($query) or die("checkProduct:".mysql_error());
			$num=mysql_num_rows($result);
			if($num==0) return true;
			else return false;
		}
		//insert a new product
		static function insertProduct($brandID,$modelID,$seriesID,$image,$quantity,$price){
			$brandID=mysql_real_escape_string(trim($brandID));
			$modelID=mysql_real_escape_string(trim($modelID));
			$seriesID=mysql_real_escape_string(trim($seriesID));
			$image=mysql_real_escape_string(trim($image));
			$quantity=mysql_real_escape_string(trim($quantity));
			$price=mysql_real_escape_string(trim($price));
			$dateAdd=time();
			$status_pr="active";
			$query="INSERT INTO tbl_product(brandID,modelID,seriesID,image,quantity,price,dateAdd,status_pr)
			VALUES('$brandID','$modelID','$seriesID','$image','$quantity','$price','$dateAdd','$status_pr')";
			//echo $query;
			$result=mysql_query($query) or die("addproduct".mysql_error());
			return $result;
			
		}
		static function checkProductDetail($productID){
			$productID=mysql_real_escape_string(trim($productID));
			$query="SELECT * FROM tbl_product_detail WHERE productID='$productID'";
			$result =mysql_query($query) or die("checkProductDetail:".mysql_error());
			$num=mysql_num_rows($result);
			if($num==0) return true;
			else return false;
		}
		//insert a new product detail
		static function insertProductDetail($productID,$screen,$cpu,$ram,$os,$sim,$camera,$memory_in,$memory_out,$cell){
			$productID=mysql_real_escape_string(trim($productID));
			$screen=mysql_real_escape_string(trim($screen));
			$cpu=mysql_real_escape_string(trim($cpu));
			$ram=mysql_real_escape_string(trim($ram));
			$os=mysql_real_escape_string(trim($os));
			$sim=mysql_real_escape_string(trim($sim));
			$camera=mysql_real_escape_string(trim($camera));
			$memory_in=mysql_real_escape_string(trim($memory_in));
			$memory_out=mysql_real_escape_string(trim($memory_out));
			$cell=mysql_real_escape_string(trim($cell));
			$query="INSERT INTO tbl_product_detail(productID,screen,cpu,ram,os,sim,camera,memory_in,memory_out,cell)
			VALUES('$productID','$screen','$cpu','$ram','$os','$sim','$camera','$memory_in','$memory_out','$cell')";
			//echo $query;
			$result=mysql_query($query) or die("addProductDetail".mysql_error());
			return $result;
			
		}
		//insert a new product detail
		static function updateProductDt($productID,$screen,$cpu,$ram,$os,$sim,$camera,$memory_in,$memory_out,$cell){
			$productID=mysql_real_escape_string(trim($productID));
			$screen=mysql_real_escape_string(trim($screen));
			$cpu=mysql_real_escape_string(trim($cpu));
			$ram=mysql_real_escape_string(trim($ram));
			$os=mysql_real_escape_string(trim($os));
			$sim=mysql_real_escape_string(trim($sim));
			$camera=mysql_real_escape_string(trim($camera));
			$memory_in=mysql_real_escape_string(trim($memory_in));
			$memory_out=mysql_real_escape_string(trim($memory_out));
			$cell=mysql_real_escape_string(trim($cell));
			$query="UPDATE tbl_product_detail SET
			screen='$screen',cpu='$cpu',ram='$ram',os='$os',sim='$sim',camera='$camera',
			memory_in='$memory_in',memory_out='$memory_out',cell='$cell' WHERE productID='$productID'";
			//echo $query;
			$result = mysql_query($query) or die("update Product detail: ".mysql_error());
			return $result;
			
		}
		//Update a product
		static function updateProduct($productID,$brandID,$modelID,$seriesID,$image,$quantity,$price,$status_pr){
			$productID=mysql_real_escape_string(trim($productID));
			$brandID=mysql_real_escape_string(trim($brandID));
			$modelI=mysql_real_escape_string(trim($modelID));
			$seriesID=mysql_real_escape_string(trim($seriesID));
			$image=mysql_real_escape_string(trim($image));
			$quantity=mysql_real_escape_string(trim($quantity));
			$price=mysql_real_escape_string(trim($price));
			$status_pr=mysql_real_escape_string(trim($status_pr));
			$dateModify=time();
			$query="UPDATE tbl_product SET
			brandID='$brandID',modelID='$modelID',seriesID='$seriesID',image='$image',quantity='$quantity',price='$price',
			dateModify='$dateModify',status_pr='$status_pr' WHERE productID='$productID'";
			//echo $query;
			$result = mysql_query($query) or die("update Product: ".mysql_error());
			return $result;
		}
		//Del a product
		static function DelProduct($productID){
			$query="DELETE FROM tbl_product WHERE productID='$productID'";
			$result=mysql_query($query) or die("DelProduct: ".mysql_error());
			return $result;
		}
	
		static function printProductTable(){
			$query= "SELECT * FROM tbl_product pr, tbl_series sr,tbl_model md,tbl_brand br ,tbl_product_detail dt
			WHERE pr.brandID=br.brandID AND pr.modelID=md.modelID AND pr.productID=dt.productID AND pr.seriesID=sr.seriesID   ORDER BY seriesName ASC";
			$result = mysql_query($query)or die("printSeriesTable: ".mysql_error());
			print ('<table id="hor-zebra">
			<thread><tr>
				<th>ID</th>
				<th>Product name</th>
				<th>Quantity</th>
				<th>Price</th>
				<th>Date Add</th>
				<th>Date Modify</th>
				<th>Status</th>
				<th colspan="3">Action</th>
			</tr></thread>
			');
			while($row=mysql_fetch_array($result)){
				print('<tbody><tr>
							<td>'.$row['productID'].'</td>
							<td>'.$row['brandName'].' '.$row['modelName'].' '.$row['seriesName'].'</td>
							<td>'.$row['quantity'].'</td>
							<td>'.number_format($row['price'],3)." VND".'</td>
							<td>'.gmdate("d/m/Y H:i A", $row['dateAdd'] + 7*3600).'</td>
							<td>'.gmdate("d/m/Y H:i A", $row['dateModify'] + 7*3600).'</td>
							<td>'.$row['status_pr'].'</td>
							<td><a href="../admin/update_product.php?productID='.$row['productID'].'">Update</a></td>
							<td><a href="../admin/update_product_dt.php?productID='.$row['productID'].'">Update Detail</a></td>
							<td><a href="../admin/del_product.php?productID='.$row['productID'].'">Delete</a></td>
							
							</tr>');}
			print('</tbody></table>');
		}
		//search

		//Danh sach san pham chua nhap chi tiet
		static function printProductTable_error(){
			$query= "SELECT * FROM tbl_product pr, tbl_series sr,tbl_model md,tbl_brand br 
			WHERE pr.brandID=br.brandID AND pr.modelID=md.modelID AND pr.seriesID=sr.seriesID AND productID NOT IN(select productID FROM tbl_product_detail)";
			$result = mysql_query($query)or die("printSeriesTable_error: ".mysql_error());
			print ('<table id="hor-zebra">
			<thread><tr>
				<th>ID</th>
				<th>Product name</th>
				<th>Quantity</th>
				<th>Price</th>
				<th>Date Add</th>
				<th>Date Modify</th>
				<th>Status</th>
				<th colspan="3">Action</th>
			</tr></thread>
			');
			while($row=mysql_fetch_array($result)){
				print('<tbody><tr>
							<td>'.$row['productID'].'</td>
							<td>'.$row['brandName'].' '.$row['modelName'].' '.$row['seriesName'].'</td>
							<td>'.$row['quantity'].'</td>
							<td>'.number_format($row['price'],3)." VND".'</td>
							<td>'.gmdate("d/m/Y H:i A", $row['dateAdd'] + 7*3600).'</td>
							<td>'.gmdate("d/m/Y H:i A", $row['dateModify'] + 7*3600).'</td>
							<td>'.$row['status_pr'].'</td>
							<td><a href="../admin/product_detail.php?seriesID='.$row['seriesID'].'">Add Detail</a></td>
							<td><a href="../admin/del_product.php?productID='.$row['productID'].'">Delete</a></td>
							
							</tr>');}
			print('</tbody></table>');
		}
		
		static function printMenuleft(){
			$query= "SELECT * FROM tbl_brand WHERE br_status='active'";
			$result = mysql_query($query)or die("printMenuleft: ".mysql_error());

			while($row=mysql_fetch_array($result)){
				print('<ul>
		
							<li><img src='.$row['br_image'].'><span></span><a href="showlistBrandname.php?brandID='.$row['brandID'].'">'.$row['brandName'].'</a></li>
							</ul>');}
		}
		static function showListProduct(){
			$query= "SELECT *,pr.image FROM tbl_product pr,tbl_model md,tbl_brand br,tbl_series sr,tbl_product_detail pr_dt 
			WHERE pr.brandID=br.brandID and pr.modelID=md.modelID and pr.seriesID=sr.seriesID AND status_pr='active' AND pr_dt.productID=pr.productID LIMIT 10 ";
			$result =mysql_query($query) or die ("showListProduct: ".mysql_error());
			print ('<div id="table">
			<ul>');
			while($row=mysql_fetch_array($result)){
				print('<li class="sp">
				<a href=productDetail.php?productID='.$row['productID'].'>
					<div><img src='.$row['image'].'></div>
					<div  class="name"><span>'.$row['brandName'].' '.$row['modelName'].' '.$row['seriesName'].'</span></div>
					<div class="price"><span>'.number_format($row['price'],3)." VND".' VND</span></div>
				</a>
				</li>');}
			print('</ul></div>');
		}
		/*static function showListProduct2(){
			$query= "SELECT max(pr.productID),brandName,modelName,seriesName,image,pr.productID,price FROM tbl_product pr,tbl_model md,tbl_brand br,tbl_series sr,tbl_product_detail pr_dt 
			WHERE pr.brandID=br.brandID and pr.modelID=md.modelID and pr.seriesID=sr.seriesID AND pr_dt.productID=pr.productID";
			$result =mysql_query($query) or die ("showListProduct: ".mysql_error());
			print ('<div id="table">
			<ul>');
			while($row=mysql_fetch_array($result)){
				print('<li class="sp">
				<div class="name"><span>'.($row['productID']).'</span></div>
					<div><img src='.$row['image'].'></div>
					<div  class="name"><span>'.$row['brandName'].' '.$row['modelName'].' '.$row['seriesName'].'</span></div>
					<div class="price"><span>'.number_format($row['price'],3).' VND</span></div>
				</a>
				</li>');}
			print('</ul></div>');
		}*/
		static function showListBrandname($brandID){
			$query= "SELECT * FROM tbl_product pr,tbl_model md,tbl_brand br,tbl_series sr,tbl_product_detail pr_dt 
			WHERE pr.brandID=br.brandID and pr.modelID=md.modelID and pr.seriesID=sr.seriesID AND pr_dt.productID=pr.productID AND br.brandID='$brandID'";
			$result =mysql_query($query) or die ("showListProduct: ".mysql_error());
			print ('<div id="table">
			<ul>');
			while($row=mysql_fetch_array($result)){
				print('<li class="sp">
				<a href=productDetail.php?productID='.$row['productID'].'>
					<div><img src='.$row['image'].'></div>
					<div  class="name"><span>'.$row['brandName'].' '.$row['modelName'].' '.$row['seriesName'].'</span></div>
					<div class="price"><span>'.number_format($row['price'],3)." VND".' VND</span></div>
				</a>
				</li>');}
			print('</ul></div>');
		}
		/* orders*/
		//get thong tin orders
		static function getInfoOrders_(){
			$query="SELECT * FROM tbl_orders ORDER BY ordersID DESC LIMIT 1 ";
			$result=mysql_query($query) or die("getInfoProduct: ".mysql_error());
			$row=mysql_fetch_array($result);
			return $row;
		}
			static function getInfoOrders($ordersID){
			$query="SELECT * FROM tbl_orders ,tbl_orders_detail ,tbl_customer,tbl_product,tbl_brand,tbl_model,tbl_series
			WHERE tbl_orders.ordersID=tbl_orders_detail.ordersID AND tbl_customer.customerID=tbl_orders.customerID AND
			tbl_product.productID=tbl_orders_detail.productID AND
			tbl_orders.ordersID='$ordersID'";
			$result=mysql_query($query) or die('getInfoOrders'.mysql_error());
			$row=mysql_fetch_array($result);
			return $row;
			}
			static function addOrders($customerID,$totalPrice){
				$customerID=mysql_real_escape_string(trim($customerID));
				$totalPrice=mysql_real_escape_string(trim($totalPrice));
				$or_dateAdd=date("U");
				$status="pending";
				$query="INSERT INTO tbl_orders(customerID,totalPrice,or_dateAdd,or_status)VALUES('$customerID','$totalPrice','$or_dateAdd','$status')";
				echo $query;
				$result =mysql_query($query) or die("addOrders".mysql_error());
				return $result;
			}
		static function addOrdersDetail($ordersID,$productID,$quantity,$price){
				$ordersID=mysql_real_escape_string(trim($ordersID));
				$productID=mysql_real_escape_string(trim($productID));
				$quantity=mysql_real_escape_string(trim($quantity));
				$price=mysql_real_escape_string(trim($price));
				$query="INSERT INTO tbl_orders_detail(ordersID,productID,or_quantity,or_price)VALUES('$ordersID','$productID','$quantity','$price')";
				echo $query;
				$result =mysql_query($query) or die("addOrdersDetail".mysql_error());
				return $result;
			}
				//Update a product
		static function updateStatusOrders($ordersID,$status,$quantity){
			$ordersID=mysql_real_escape_string(trim($ordersID));
			$status=mysql_real_escape_string(trim($status));
			$or_dateModify=date("U");
			$query="UPDATE tbl_orders ors,tbl_product prs,tbl_orders_detail dt SET ors.or_status='$status',or_dateModify='$or_dateModify',prs.quantity='$quantity' WHERE dt.productID=prs.productID  AND ors.ordersID='$ordersID'";
			$result = mysql_query($query) or die("update Status Orders: ".mysql_error());
			return $result;
		}

		static function orders_Detail($ordersID){
			$query="
			SELECT *FROM tbl_orders ,tbl_orders_detail,tbl_brand,tbl_model,tbl_series,tbl_product  WHERE 
			 tbl_orders.ordersID=tbl_orders_detail.ordersID AND 
			 tbl_product.productID=tbl_orders_detail.productID AND
			 tbl_brand.brandID=tbl_product.brandID AND
			 tbl_model.modelID=tbl_product.modelID AND
			 tbl_series.seriesID=tbl_product.seriesID AND
			 tbl_orders.ordersID='$ordersID'  ORDER BY tbl_orders_detail.ordersID DESC";
			//AND ors.status!='revoke'
			$result=mysql_query($query) or die("orders".mysql_error());
				print ('<table id="hor-zebra">
			<thread><tr>
				<th>Order ID</th>
				<th>Product Name</th>
				<th>Quantity</th>
				<th>Price</th>
				<th>Total Price</th>
			</tr></thread>
			');
			$value=0;
			while($row=mysql_fetch_array($result)){
			//$get=Product::getInfoProduct($row['productID']);
				print ('<tbody>');
				if($value%2==0){echo '<tr class="tr-1">';}
				else {echo '<tr class="tr-2">';}
				print ('
							<td>'.$row['ordersID'].'</td>
							<td>'.$row['brandName'].' '.$row['modelName'].' '.$row['seriesName'].'</td>
							<td>'.$row['or_quantity'].'</td>
							<td>'.number_format($row['or_price'],3)." VND".'</td>
							<td>'.number_format($row['or_price']*+$row['or_quantity'],3)." VND".'</td>
							
							');
							
			$value+=1;
							}
			print('</tbody></table>');
		}
		/**/
	}
?>